local pinghe = fk.CreateSkill {

  name = "joy__pinghe",

  tags = { Skill.Compulsory, },

}



pinghe:addEffect(fk.DamageInflicted, {
  name = "joy__pinghe",
  events = {fk.DamageInflicted},
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return
      target == player and
      player:hasSkill(pinghe.name) and
      player.maxHp > 1 and
      not player:isKongcheng() and
      data.from and
      data.from ~= player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, -1)
    local tos, cardId = room:askForChooseCardAndPlayers(player, table.map(room:getOtherPlayers(player, false), function(p)
      return p.id end), 1, 1, ".|.|.|hand", "#joy__pinghe-give", pinghe.name, false, true )
    room:obtainCard(tos[1], cardId, false, fk.ReasonGive)
    if player:hasSkill(yingba.name, true) and data.from:isAlive() then
      room:addPlayerMark(data.from, "@joy__yingba_pingding")
    end
    return true
  end,
})

pinghe:addEffect("maxcards", {
  name = "#joy__pinghe-buff",
  frequency = Skill.Compulsory,
  fixed_func = function(self, player)
    return player:hasSkill("joy__pinghe") and player:getLostHp() or nil
  end
})

return pinghe